<?php
include "includes/db.php";
$mysqli = new MossCMS();

if ($_SESSION[$prefix.'_username'] == ""){  header("Location: login.php"); exit;}

$in_id = (int)$_GET['id'];
if($in_id != ''){
	$page_info = $mysqli->pages_info($in_id);
	$display_page = 1;
}

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Moss, Inc - Portal</title>
<link href="includes/sw_orig.css" rel="stylesheet" type="text/css" media="screen" />
<link href="includes/local.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="container">
  <div id="header">
  <?php include "includes/header.php"; ?>
	</div>


<div id="mainContent" class="frontpage">
<?php if($display_page == 1){ ?>

<h1><?php echo $page_info['page_name'];?></h1>
<br>
<?php
$file = $page_info['page_content'];
$handle = fopen($file, "r");
$output = fread($handle, filesize($file));
echo $output;
?>  

<?php } else{ ?>

<h1>Pages</h1>
<br>

 <table class="underline">
          <thead>
          <tr>
          	<th>Title</th>
            <th>Last Update</th>
          </tr>
          </thead>
          <tbody>
          <?php
			$results = $mysqli->pages_list();
      			for($x=0; $x < sizeof($results); $x++) {
				if($class == 'row2'){$class = 'row1';}else{$class = 'row2';}

			$date = date('m/d/Y H:i:s',(strtotime($results[$x]['page_timestamp'])));
			$title_link = "<a href='../article.php?id=".$results[$x]['page_id']."'>".$results[$x]['page_name']."</a>";

					
		$edit_link = "<a href ='pages.php?id=".$results[$x]['page_id']."'>$icon_edit</a>";
		$edit_title = "<a href ='pages.php?id=".$results[$x]['page_id']."'>".$results[$x]['page_name']."</a>";
		$delete_link = "<a href =\"javascript:;\" onclick=\"assure(". $results[$x]['content_id'].");\">$icon_delete</a>";
		//echo "<tr class='$class'><td>".$edit_title."</td><td>".$img_link."</td><td>".$date."</td><td>".$edit_link.$delete_link."</td></tr>";
			?>
			<tr class="<?php echo $class;?>">
				<td><?php echo $edit_title;?></td>
				<td><?php echo $date;?></td>
			</tr>
			<?php } ?>
			            
    	</tbody>
        </table>

<?php } ?>
            
		<div class="clear"></div>	

 
<div id="footer">
	<?php include "includes/footer.php"; ?>
</div>
<!-- end #container --></div>

<br />
</body>
</html>
